import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;

// 主游戏窗口
public class CardGame extends JFrame {
    public CardGame() {
        setTitle("2D卡牌游戏");
        setSize(800, 600);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        add(new CardGamePanel()); // 直接使用内部类
        setLocationRelativeTo(null);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            new CardGame().setVisible(true);
        });
    }

    // 游戏主面板
    class CardGamePanel extends JPanel {
        private List<Card> playerHand;
        private List<Card> enemyField;
        private List<Card> playerField;

        public CardGamePanel() {
            playerHand = new ArrayList<>();
            enemyField = new ArrayList<>();
            playerField = new ArrayList<>();

            // 初始化一些测试卡牌
            initializeCards();

            // 添加鼠标监听器处理卡牌点击
            addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent e) {
                    // 处理卡牌点击逻辑
                    repaint();
                }
            });
        }

        private void initializeCards() {
            playerHand.add(new Card("火球术", 3, 0));
            playerHand.add(new Card("治疗术", 0, 4));
            playerHand.add(new Card("剑士", 2, 3));
        }

        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;

            // 绘制手牌区域
            drawHandCards(g2d);

            // 绘制场上卡牌
            drawFieldCards(g2d);
        }

        private void drawHandCards(Graphics2D g2d) {
            int x = 50;
            int y = 400;

            for (int i = 0; i < playerHand.size(); i++) {
                Card card = playerHand.get(i);
                g2d.setColor(Color.BLUE);
                g2d.fillRect(x + i * 110, y, 100, 150);
                g2d.setColor(Color.WHITE);
                g2d.drawString(card.getName(), x + i * 110 + 10, y + 20);
                g2d.drawString("攻:" + card.getAttack(), x + i * 110 + 10, y + 40);
                g2d.drawString("血:" + card.getHealth(), x + i * 110 + 10, y + 60);
            }
        }

        private void drawFieldCards(Graphics2D g2d) {
            // 绘制逻辑类似手牌
        }
    }

    // 简单的卡牌类
    class Card {
        private String name;
        private int attack;
        private int health;
        private ImageIcon image;

        public Card(String name, int attack, int health) {
            this.name = name;
            this.attack = attack;
            this.health = health;
        }

        // getters and setters
        public String getName() { return name; }
        public int getAttack() { return attack; }
        public int getHealth() { return health; }
    }
}
